<?php

namespace App\Http\Livewire\Archives;

use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Livewire\Component;

class Edit extends Component
{
    use AuthorizesRequests;
    public $archive;
    public $title;
    public $content;
    public function mount()
    {
        // dd($this->archive->toArray());

        $this->fill($this->archive->toArray());
    }

    public function save()
    {
        $this->authorize('update', $this->archive);
        $this->validate([
            'title' => 'required|between:5,255',
            'content' => 'nullable|min:10,1024'
        ]);
        $this->archive->title = $this->title;
        $this->archive->content = $this->content;
        $this->archive->save();
        $this->emit('showMessage', [
            'title' => null,
            'content' => '文档信息已变更',
            'type' => 'info',
            'timeout' => 3000,
            'revoke' => false,
        ]);
    }
    public function render()
    {
        return view('livewire.archives.edit');
    }
}
